package com.mc.lp.shared.service.executor;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;

/**
 * executor service to handle tasks required to run asynchronously.
 * @author deepak
 *
 */
public class ExecutorServiceProxy implements IExecutorService{
	private ExecutorService executor = Executors.newFixedThreadPool(50);
	@SuppressWarnings("unchecked")
	public <E> Future<E> submitTask(FutureTask<E> task){
		//for safer side we will start the service again if it is terminated by any reason.
		if(executor.isShutdown() || executor.isTerminated())
			executor= Executors.newFixedThreadPool(10);
		return (Future<E>) executor.submit(task);
	}
	
	public <E> void executeTask(FutureTask<E> task){
		//for safer side we will start the service again if it is terminated by any reason.
		if(executor.isShutdown() || executor.isTerminated())
			executor= Executors.newFixedThreadPool(10);
		
		executor.execute(task);
	}
}

